package flc.ast.dialog;

import android.content.Context;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.lxj.xpopup.core.AttachPopupView;

import java.util.ArrayList;
import java.util.List;

import flc.ast.R;
import flc.ast.adapter.SelStarAdapter;
import stark.common.basic.view.container.StkRecycleView;

public class SelStarDialog extends AttachPopupView {

    private SelStarAdapter selStarAdapter;
    private StkRecycleView rvSelStarList;

    public SelStarDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected int getImplLayoutId() {
        return R.layout.dialog_sel_star;
    }

    @Override
    protected void onCreate() {
        super.onCreate();
        initView();
    }

    protected void initView() {
        rvSelStarList = (StkRecycleView) findViewById(R.id.rvSelStarList);
        rvSelStarList.setLayoutManager(new LinearLayoutManager(getContext()));
        selStarAdapter = new SelStarAdapter();
        rvSelStarList.setAdapter(selStarAdapter);
        selStarAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
                dismiss();
                if (listener != null) {
                    listener.onClick(selStarAdapter.getItem(position));
                }
            }
        });
        setData();
    }

    private void setData() {
        List<String> list = new ArrayList<>();
        list.add(getContext().getString(R.string.star_sign1));
        list.add(getContext().getString(R.string.star_sign2));
        list.add(getContext().getString(R.string.star_sign3));
        list.add(getContext().getString(R.string.star_sign4));
        list.add(getContext().getString(R.string.star_sign5));
        list.add(getContext().getString(R.string.star_sign6));
        list.add(getContext().getString(R.string.star_sign7));
        list.add(getContext().getString(R.string.star_sign8));
        list.add(getContext().getString(R.string.star_sign9));
        list.add(getContext().getString(R.string.star_sign10));
        list.add(getContext().getString(R.string.star_sign11));
        list.add(getContext().getString(R.string.star_sign12));
        selStarAdapter.setList(list);
    }

    private Ilistener listener;

    public void setListener(Ilistener listener) {
        this.listener = listener;
    }

    public interface Ilistener {
        void onClick(String name);
    }


}
